package com.sun.controller.admin;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.pojo.Menu;
import com.sun.pojo.Role;
import com.sun.pojo.Room;
import com.sun.service.MenuService;
import com.sun.service.RoleService;
import com.sun.service.RoomService;
import com.sun.utils.DataGridViewResult;
import com.sun.utils.SystemConstant;
import com.sun.utils.TreeNode;
import com.sun.vo.RoleVo;
import com.sun.vo.RoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/room")
public class RoomAdminController {

    @Autowired
    private RoomService roomService;

    @RequestMapping("/findAll")
    public DataGridViewResult findAll(RoomVo roomVo){
        return roomService.findAll(roomVo);
    }

    @RequestMapping("/addRoom")
    public String addRoom(Room room){
        HashMap<String, Object> map = new HashMap<String, Object>();
        if(roomService.addRoom(room)>0){
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"添加成功!");
        }else{
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"添加失败!");
        }
        return JSON.toJSONString(map);
    }

    @RequestMapping("/updateRoom")
    public String updateRoom(Room room){
        HashMap<String, Object> map = new HashMap<String, Object>();
        if(roomService.updateRoom(room)>0){
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"修改成功!");
        }else{
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"修改失败!");
        }
        return JSON.toJSONString(map);
    }

    @RequestMapping("/deleteRoom")
    public String deleteRoom(int id){
        HashMap<String, Object> map = new HashMap<String, Object>();
        if(roomService.deleteRoom(id)>0){
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"删除成功!");
        }else{
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"删除失败!");
        }
        return JSON.toJSONString(map);
    }
}
